var Minio = require("minio");

const bucketName = "d8dweb";
const accessKey = "KJW2X7HOXXL9yG2C2X1Q";
const secretKey = "fRxkjTHAOTza1ZDiKLotVKrDIcvYphwvCWsTmQCV";

var minioClient = new Minio.Client({
  endPoint: "localhost",
  port: 23898,
  useSSL: false,
  accessKey: accessKey,
  secretKey: secretKey,
});

async function getList() {
  // 使用回调函数的方式列出对象
  minioClient
    .listObjects(bucketName, "", true)
    .on("data", function (obj) {
      console.log("对象:", obj);
    })
    .on("error", function (err) {
      console.log("错误:", err);
    });
}
// getList();

async function getTemporaryCredentials() {
  const policy = minioClient.newPostPolicy();

  // Policy restricted only for bucket 'mybucket'.
  policy.setBucket(bucketName);

  // Policy restricted only for hello.txt object.
  // policy.setKey("hello.txt");

  const { postURL, formData } = await minioClient.presignedPostPolicy(policy);

  console.log("临时凭证:", postURL, formData);
}

getTemporaryCredentials();
